﻿@page "/"

<PageTitle>文件上传</PageTitle>


<InputFile OnChange="Upload" />
@if (uploaded)
{
    <div class="alert alert-success">上传成功</div>
}
@inject HttpClient Client;
@code {
    bool uploaded;
    async Task Upload(InputFileChangeEventArgs e)
    {
        uploaded = false;

        using var mediaContent = new MultipartFormDataContent();
        using var streamContent = new StreamContent(e.File.OpenReadStream(2048000));
        streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(e.File.ContentType);

        mediaContent.Add(streamContent, "\"files\"", e.File.Name);

        var response= await Client.PostAsync("/upload", mediaContent);
        response.EnsureSuccessStatusCode();

        uploaded = true;
    }
}